<template>
  <div class="AddOrUpdate_main add_container column_two tenantMenu_main main_container">
    <div class="formItem_header">
      订单明细
      <div class="formItem_header_operate">
        <a class="formItem_header_operate_item" @click="addRow">
          <svg-icon icon-class="新增" />
          <div class="item_name">添加</div>
        </a>
      </div>
    </div>
    <div class="main_main">
      <div
        ref="table_container"
        class="table_container"
      >
        <el-table
          ref="table"
          :data="tableData"
          stripe
          border
          row-key="id"
          style="width: 99.9%;"
          :height="tableHeight"
          @sort-change="(column)=>{sortChange(column, this)}"
          @selection-change="(val)=>{selectionChange(val, this)}"
        >
          <Column v-for="(column,index) in defaultTableColumns" :key="index" :prop="column.prop" :is-show="column.isShow" :label="column.label" :sortable="column.sortable" :width="column.width" />
          <el-table-column label="操作" align="center" fixed="right" width="120">
            <template slot-scope="scope">
              <el-button
                type="text"
                @click.stop="edit(scope.row)"
              >编辑</el-button>
              <el-button
                type="text"
                @click.stop="deleteOne(scope.row,scope.$index)"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import { list, remove } from '@/api/superManage/reportForm'
import AddOrUpdate from '../reportForm/addOrUpdate.vue'
export default {
  name: 'AddOrUpdate',
  props: {
    layerid: {},
    id: {},
    tenantId: {},
    defaultValue: {}
  },
  data() {
    return {
      pageData: {
        pageNum: 1,
        pageSize: 9999,
        orderByColumn: 'updateTime',
        isAsc: 'desc'
      },
      defaultTableColumns: [// 表格常规字段（初始值）
        { prop: 'name', label: '模版名称' },
        { prop: 'reportId', label: '报表id' },
        { prop: 'menuPath', label: '菜单路由' },
        // { prop: 'tenantId', label: '租户id' },
        { prop: 'viewPath', label: '视图id' }
      ],
      formData: {},
      noChooseList: [],
      selections: [], // 表格当前页所选中的行
      selectionsAll: [], // 表格所有页选中的行
      listData: [],
      taxRateCodeList: [],
      tableHeight: '0',
      templateSelection: '',
      tableData: [],
      mainId: 'id'
    }
  },
  created() {
    this.getList()
  },
  mounted() {
    this.$nextTick(() => {
      this.tableHeight = this.$refs.table_container.offsetHeight
    })
  },
  methods: {
    addRow() {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
            tenantId: this.tenantId
          }// props
        },
        area: ['440px', '450px'],
        title: '新增打印设置', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    getList() {
      list({ tenantId: this.tenantId }).then((res) => {
        this.tableData = res.data
      })
    },
    deleteOne(row) {
      const _this = this
      this.$confirm('确定要删除吗', '删除确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消', cancelButtonClass: 'cancelConfirm',
        type: 'warning'
      }).then(function() {
        remove(row.id).then(res => {
          _this.$message({
            message: res.msg,
            type: 'success'
          })
          _this.getList()
        })
      }).catch(() => {})
    },
    refresh() {
      this.pageData.pageNum = 1
      this.getList()
    },
    edit(row) {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
            id: row[this.mainId]
          }// props
        },
        area: ['440px', '450px'],
        title: '编辑打印设置', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    // 提交
    // onSubmit() {
    //   const list = this.listData.filter(item => {
    //     return !this.selections.includes(item)
    //   })
    //   this.selections.forEach(ele => {
    //     ele.status = '3'
    //   })
    //   list.push(...this.selections)
    //   this.formData.data = this.$deepClone(list)
    //   addOrUpdate(this.formData).then((res) => {
    //     this.$message({
    //       message: res.msg,
    //       type: 'success'
    //     })
    //     this.$layer.close(this.layerid) // 关闭弹框
    //     this.$parent.getList() // 调用父组件的刷新方法
    //   })
    // },
    cancel() {
      this.$layer.close(this.layerid) // 关闭弹框
    }

  }
}
</script>

<style lang="less" scoped>
.form_padding{
  padding: 0 !important;
}
.title {
  padding-left: 10px;
  padding-bottom: 20px;
  font-size: 24px;
  width: 100%;
}
.numberComponents {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
}
/deep/ .el-input-number.is-controls-right .el-input-number__increase {
  height: 15px;
}
.el-icon-remove {
  font-size: 25px;
  color: red;
  height: 100%;
  width: 100%;
  border: 0px;
  background-color: transparent;
}
/deep/ .el-form-item__content {
  margin-left: 0 !important;
}
/deep/ .el-form-item__label {
  text-align: right;
}
.expand_radio {
  /deep/ .el-form-item__content {
    text-align: left;
  }
}
.expand_container {
  .el-form-item {
    margin-bottom: 10px;
  }
  .expand_file {
    margin-bottom: 0px;
  }

  /deep/ .el-form-item__label {
    width: 130px !important;
  }
  /deep/ .el-form-item__content {
    width: 710px !important;
  }
}
.main_main {
  margin: 0 !important;
  padding: 0 !important;
  .table_container{
    margin-top: 0 !important;
  }
  .form_padding {
    /deep/ .el-form-item {
      margin-right: 0px;
    }
    /deep/ .el-form-item__label {
      width: 120px !important;
    }
    /deep/ .el-form-item__content {
      width: 270px;
    }
    .remark {
      /deep/ .el-form-item__content {
        width: 690px !important;
        height: 60px;
        overflow-y: auto;
      }
    }
  }
}
/deep/ .el-table th.el-table__cell > .cell {
  position: unset;
}
.order_header{
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  .info_button{
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
  }
}
    .formItem_header{
      font-size: 18px;
      width: 100%;
      height: 50px;line-height: 50px;
      padding-left: 20px;
      padding-right: 20px;
      display: flex;justify-content: space-between;align-items: center;
      .formItem_header_operate{
        display: flex;
        .formItem_header_operate_item{
          height: 30px;
          display: flex;justify-content: center;align-items: center;
          padding: 0px 10px;font-size: 16px;margin-left: 10px;border-radius: 4px;
          color: rgba(56, 123, 252, 1);background-color: rgba(235, 242, 255, 1);
          .item_name{
            font-size: 14px;padding-left: 10px;
          }
        }
        .formItem_header_operate_item:hover{
          background-color: rgba(235, 242, 255, 0.5);
        }
        .delete{
          color: rgba(255, 70, 70, 1);background-color: rgba(235, 242, 255, 1);
        }
        .delete:hover{
          background-color: rgba(235, 242, 255, 0.5);
        }
      }
    }
</style>
